package controller.tcc.ada.ifmg.edu.br;

import persistence.tcc.ada.ifmg.edu.br.PersistenceHelper;
import tcc.ada.ifmg.edu.br.R;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v4.widget.CursorAdapter;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListaDeAlunosAdapter extends BaseAdapter{
	private Context mContext;
	private ListView listaDeAlunos;
	private PersistenceHelper helper;
	private SQLiteDatabase database;
	private CursorAdapter dataSource;
	
	private final String[] camposTable = {"nome_aluno","sobrenome_aluno", "email_aluno"};
	
	public ListaDeAlunosAdapter(Context c){
		mContext = c;
		helper = PersistenceHelper.getInstance(c);
		database = helper.getWritableDatabase();
	}
	
	private void carregarListaDeAlunos(){
		Cursor alunos = database.query("tb_alunos", camposTable, null, null, null, null, null);
		if(alunos.getCount() > 0){
			dataSource = new SimpleCursorAdapter(mContext, R.layout.adapter_aluno_listview, alunos, camposTable, new int[]{R.id.nome_aluno_adapterlist, R.id.email_aluno_adapterlist} );
			listaDeAlunos.setAdapter(dataSource);
		} else {
			Toast.makeText(mContext, "Nenhum registro encontrado", Toast.LENGTH_SHORT);
		}
		database.close();
	}

	@Override
	public int getCount() {
		
		return 0;
	}

	@Override
	public Object getItem(int position) {
		
		return null;
	}

	@Override
	public long getItemId(int position) {
		
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		return null;
	}
	
	
	
	
}
